// 登录注册页面的手机号验证

window.addEventListener('load', function () {
    var reg_user = /^[\u4e00-\u9fa5]{2, 4}$/;    //2-4个中文字符正则
    var reg_tel = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;    //11位手机号码正则
    var display = document.querySelector('.display');
    var display_icon = document.querySelector(".display_icon");

    //手机号格式验证
    function checkSubmit() {
        if (tel.value == "") {
            display.className = "error";
            display.innerHTML = "手机号码格式不正确,请重新输入";
            display_icon.className = "error_icon";

        } else if (!reg_tel.test(tel.value)) {
            display.className = "error";
            display_icon.className = "error_icon";
            display.innerHTML = "手机号码格式不正确,请重新输入";
        }
        else {
            display.className = "success";
            display.innerHTML = "手机号码格式输入正确";
            display_icon.className = "success_icon";
        }
    }

    var tel = document.querySelector('.tel');
    tel.addEventListener('keyup', function () {
        checkSubmit();
    })

    //获取cookie代码
    var getCookie = function (name) {
        var arr;
        var reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
        if (arr = document.cookie.match(reg)) {
            return arr[2];
        }
        else {
            return null;
        }
    };

    //点击获取按钮之后调用的函数
    var login = document.querySelector("#login");
    var landing = document.querySelector("#landing");
    var password_icon = document.querySelector("#password_icon");
    var password_text = document.querySelector("#password_text");
    login.addEventListener("click", function () {
        if (getCookie("password") == landing.value) {
            alert("登录成功");
            window.location.href = 'index.html';
        }
        else {
            password_icon.className = "error_icon";
            password_text.className = "error";
            password_text.innerHTML = "密码错误";
        }
    })
})

